package com.yiwei.ydd.view;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.yiwei.ydd.R;
import com.yiwei.ydd.activity.PacketRechargeActivity;
import com.yiwei.ydd.adapter.RegisterDialogAdapter;
import com.yiwei.ydd.api.model.PopBigGifModel;
import com.yiwei.ydd.util.Util;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by xsooy-pc on 2017/4/24.
 */

public class RegisterSuccessDialog extends Dialog {


    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.btn_close)
    ImageView btnClose;
    private Context context;

    private RegisterDialogAdapter registerDialogAdapter;

    public RegisterSuccessDialog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public RegisterSuccessDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_register_success);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = (int) (Util.getDisplayMetrics(context).widthPixels * 0.85);
        mWindow.setAttributes(lp);

        registerDialogAdapter = new RegisterDialogAdapter(context);
        registerDialogAdapter.setOnChooseListener(new RegisterDialogAdapter.OnChooseListener() {
            @Override
            public void onClick(String name) {
                Util.startActivity(context, PacketRechargeActivity.class);
                dismiss();
            }
        });
        list.setAdapter(registerDialogAdapter);
    }

    public RegisterSuccessDialog setData(List<PopBigGifModel.DatasBean> data) {
        registerDialogAdapter.update(data);
        return this;

    }


    private DialogDefaultClickListener listener;

    public RegisterSuccessDialog setDialogClickListener(DialogDefaultClickListener listener) {
        this.listener = listener;
        return this;
    }

    @OnClick({R.id.btn_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_close:
                dismiss();
                break;
        }
    }


    public interface DialogDefaultClickListener {
        public abstract void confirm(String money);
    }
}
